import Foundation





/*
 Possible Endpoints
 Any category, English
 https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit
 
 Single category, English
 https://v2.jokeapi.dev/joke/Programming?blacklistFlags=nsfw,religious,political,racist,sexist,explicit
 
 Any Category, language other than english
 https://v2.jokeapi.dev/joke/Any?lang=fr&blacklistFlags=nsfw,religious,political,racist,sexist,explicit
 
 Single Category, language other than english
 https://v2.jokeapi.dev/joke/Programming?lang=fr&blacklistFlags=nsfw,religious,political,racist,sexist,explicit
 
 */

func getJoke() async throws -> Joke {
//    let url = "https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit"
//    let url = "https://v2.jokeapi.dev/joke/\(Category.Pun)?blacklistFlags=nsfw,religious,political,racist,sexist,explicit"
//    let url = "https://v2.jokeapi.dev/joke/Any?lang=\(Language.cs)&blacklistFlags=nsfw,religious,political,racist,sexist,explicit"
    let url = "https://v2.jokeapi.dev/joke/\(Category.Misc)?lang=\(Language.fr)&blacklistFlags=nsfw,religious,political,racist,sexist,explicit"
    let apiService = APIService(urlString: url)
    do {
        return try await apiService.getJSON()
    } catch {
        throw error
    }
}

Task {
    do {
        let joke = try await getJoke()
        print(joke.setup ?? "")
        print(joke.delivery ?? "")
        print(joke.joke ?? "")
    } catch {
        print(error.localizedDescription)
    }
}
